#include<bits/stdc++.h>
#define ll long long
using namespace std;

const ll N = 1e6 + 10;

ll n, m;
vector<pair<ll, ll>> g[N];
ll in[N], outdeg[N];
long double p[N]; // 概率
long double ans = 0;

void solve()
{
    cin >> n >> m;
    for (ll i = 1; i <= m; i++) {
        ll x, y, w;
        cin >> x >> y >> w;
        g[x].push_back({ y, w });
        in[y]++;
        outdeg[x]++;
    }

    queue<ll> q;
    q.push(1);
    p[1] = 1.0L; // 起点概率为1

    while (!q.empty()) {
        ll x = q.front(); q.pop();
        if (outdeg[x] == 0) continue; // 终点
        long double step = p[x] / (long double)outdeg[x];
        for (auto [y, w] : g[x]) {
            ans += step * (long double)w; // 期望累加
            p[y] += step; // 概率传递
            in[y]--;
            if (in[y] == 0) q.push(y);
        }
    }

    cout << fixed << setprecision(2) << (double)ans << "\n";
}

int main()
{
    solve();
}
